package main

import (
	"bytes"
	"encoding/json"
	"golang.org/x/net/context"
	"google.golang.org/grpc"
	"log"
	"testRpc/zybRpcProto"
	"time"

	"fmt"
)

const (
	// gRPC 服务地址
	Address = "0.0.0.0:7788"
)

func main() {
	fmt.Println("start RpcClient...")
	fmt.Printf("connect to server[%s]...", Address)
	conn, err := grpc.Dial(Address, grpc.WithInsecure())
	if err != nil {
		log.Fatalln(err)
	}

	defer conn.Close()
	c := zybRpcProto.NewZybRpcClient(conn)
	req := &zybRpcProto.OrderReq{
		AccountId:  250000000003,
		GoodsId:    95,
		OrderQty:   1,
		OrderPrice: 1800,
		BuyOrSell:  1,
	}

	go func() {
		for i := 0; i < 100000; i++ {
			if rsp, err := c.SendOrder(context.Background(), req); err == nil {
				if buf, err := json.Marshal(rsp); err == nil {
					var out bytes.Buffer
					json.Indent(&out, buf, "", " ")
					fmt.Println(out.String())
				}
			} else {
				fmt.Println(err)
				//break
			}

			time.Sleep(time.Second*3)
		}
	}()

	time.Sleep(time.Minute * 10000)
}
